package com.evil.common.rocketmq.enums;

import com.evil.common.core.enums.BaseEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * 企业MQ操作tag
 *
 * @author liyang
 * @date 2025-03-06 18:23
 */
@Getter
@AllArgsConstructor
public enum EnterpriseMqOpTagEnum implements MqOpTagBaseEnum {

    /**
     * 企业MQ操作tag
     */
    ADD("ADD", "新增"),
    MODIFY("MODIFY", "编辑"),
    DELETE("DELETE", "删除"),
    ENABLE("ENABLE", "状态"),
    ;
    private final String tag;
    private final String title;

    public static Optional<EnterpriseMqOpTagEnum> isExistByTag(String tag) {
        if (StringUtils.isBlank(tag)) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.tag.equals(tag)).findFirst();
    }

    public static EnterpriseMqOpTagEnum findByTag(String key) {
        return EnterpriseMqOpTagEnum.isExistByTag(key).orElseThrow(() ->
                new BusinessException(BaseEnum.ERROR_PARAMETER, "企业MQ操作tag参数错误"));
    }
}
